﻿using SecurityAdmin.Web.Models;
using SecurityApi.DataAccess;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Web;
using System.Web.Mvc;
using Kendo.Mvc;
using Kendo.Mvc.Extensions;
using Kendo.Mvc.Infrastructure;
using Kendo.Mvc.UI;

namespace SecurityAdmin.Web.Controllers
{
    public class ResourceController : BaseController
    {
        public JsonResult AjaxGetResouceList()
        {
            ResourceRepository resourceRepository = new ResourceRepository();

            IQueryable<Resource> resourceList = resourceRepository.GetResources(SelectedApplication.ApplicationId);

            List<Resource> result = resourceList.OrderBy(p => p.Name).ToList();

            //HACK, not a elegant design
            if (null == Session["SELECTED-RESOURCE"] && result.Count > 0)
            {
                Session["SELECTED-RESOURCE"] = result[0].ResourceId;
            }
            return Json(result, JsonRequestBehavior.AllowGet);
        }

    }
}
